package offer.singleLinkedList;

/**
 * Description：倒序打印 前m个 链表元素
 * Author: zhangc
 * Date：2017/8/22 22:14
 */
public class PrintListN {

    public static <T> void printList(Node<T> head, int m) {
        if (head != null && m > 0) {
            printList(head.next, --m);
            System.out.print(head.value + " ");
        }
    }

    public static void main(String[] args) {
        Node<Integer> head = new Node<>(0);
        Node<Integer> temp = head;
        for (int i = 1; i < 10; i++) {
            temp.next = new Node<>(i);
            temp = temp.next;
        }
        temp = head;
        while (temp != null) {
            System.out.print(temp.value + " ");
            temp = temp.next;
        }
        System.out.println();
        System.out.println("====================");
        printList(head, 5);
    }

}
